#!/bin/sh
###############################################################################
##  Author    : xuezhoyi
##  Name      : dis_data_sync.sh
##  Functions : 
##  Purpose   : 
##  Revisions or Comments
##  VER        DATE        AUTHOR           DESCRIPTION
##---------  ----------  ---------------  ------------------------------------ 
##  1.0      2017-12-29  xuezhouyi        每周六数据同步到DIS
##  1.1      2018-01-12  xuezhouyi        每天下午五点数据同步到MySQL库
###############################################################################

# 路径
V_DUMP=$DWHDP_HOME/core/mysql/bin/
V_PATH=/home/hadoop/dev/data/dis/

# 源头
V_FROM_HOST=192.168.11.11
V_FROM_USER=root
V_FROM_PSWD=root

# 目标
V_TO_HOST=192.168.11.9
V_TO_USER=root
V_TO_PSWD=root

# 参数判断
if [[ ${1} != 'down' && ${1} != 'up' ]];then
    echo "参数错误!"
    exit 1
fi

# 进行同步
case ${1} in
    down)
        # 文件名
        V_DUMP_FILE="${V_PATH}DIS_DOWN_SYNC_$(date +%Y%m%d%H%M%S).DMP"

        # 卸数
        ${V_DUMP}mysqldump -h${V_FROM_HOST} -u${V_FROM_USER} -p${V_FROM_PSWD} EDW CM_RPY_WEBSITE_INFO CM_RPY_MACHINE_TOOLS FM_RPY_ENVBLD_RURAL_STATIC_MID > "${V_DUMP_FILE}"

        # 装载
        mysql -u${V_TO_USER} -p${V_TO_PSWD} EDW < "${V_DUMP_FILE}"

        # 标志
        V_OK_FILE="${V_PATH}DIS_DOWN_SYNC_$(date +%Y%m%d%H%M%S).OK"
        touch ${V_OK_FILE}
    ;;
    up)
        # 文件名
        V_DUMP_FILE="${V_PATH}DIS_UP_SYNC_$(date +%Y%m%d%H%M%S).DMP"
        
        # 卸数
        ${V_DUMP}mysqldump -u${V_TO_USER} -p${V_TO_PSWD} STG > "${V_DUMP_FILE}"
        
        # 装载
        mysql -h${V_FROM_HOST} -u${V_FROM_USER} -p${V_FROM_PSWD} STG < "${V_DUMP_FILE}"
        
        # 标志
        V_OK_FILE="${V_PATH}DIS_UP_SYNC_$(date +%Y%m%d%H%M%S).OK"
        touch ${V_OK_FILE}
    ;;
esac
